﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace HoangPhap.Bussiness
{
    public class ArticleTranslations
    {
        public List<EntityClasses.ArticleTranslation> SelectAllResults()
        {
            var lst = new List<EntityClasses.ArticleTranslation>();
            var ct = new Data.HoangPhapDataContext().GetArticleTranslationsSelectAllResults();
            if (ct.Rows.Count > 0)
            {
                lst.AddRange(from DataRow dt in ct.Rows
                             select new EntityClasses.ArticleTranslation
                             {
                                 Id = Convert.ToInt32(dt["Id"].ToString()),
                                 Body = dt["Body"].ToString(),
                                 Description = dt["Description"].ToString(),
                                 Title = dt["Title"].ToString()
                             });
            }
            return lst; 
        }

        public List<EntityClasses.ArticleTranslation> SelectByArticleEntityIdResults(System.Int32 articleEntityId)
        {
            var lst = new List<EntityClasses.ArticleTranslation>();
            var ct = new Data.HoangPhapDataContext().GetArticleTranslationsSelectByArticleEntityIdResults(articleEntityId);
            if (ct.Rows.Count > 0)
            {
                lst.AddRange(from DataRow dt in ct.Rows
                             select new EntityClasses.ArticleTranslation
                             {
                                 Id = Convert.ToInt32(dt["Id"].ToString()),
                                 Body = dt["Body"].ToString(),
                                 Description = dt["Description"].ToString(),
                                 Title = dt["Title"].ToString()
                             });
            }
            return lst; 
        }

        public EntityClasses.ArticleTranslation SelectByIdResults(System.Int64 id)
        {
            var lst = new EntityClasses.ArticleTranslation();
            var ct = new Data.HoangPhapDataContext().GetArticleTranslationsSelectByIdResults(id);
            if (ct.Rows.Count <= 0) return lst;

            lst = new EntityClasses.ArticleTranslation
            {
                Id = Convert.ToInt32(ct.Rows[0]["ID"].ToString()),
                Body = ct.Rows[0]["Body"].ToString(),
                Description = ct.Rows[0]["Description"].ToString(),
                Title = ct.Rows[0]["Title"].ToString()
            };
            return lst;
        }

        public List<EntityClasses.ArticleTranslation> SelectByLanguageIdResults(System.Int32 languageId)
        {
            var lst = new List<EntityClasses.ArticleTranslation>();
            var ct = new Data.HoangPhapDataContext().GetArticleTranslationsSelectByLanguageIdResults(languageId);
            if (ct.Rows.Count > 0)
            {
                lst.AddRange(from DataRow dt in ct.Rows
                             select new EntityClasses.ArticleTranslation
                             {
                                 Id = Convert.ToInt32(dt["Id"].ToString()),
                                 Body = dt["Body"].ToString(),
                                 Description = dt["Description"].ToString(),
                                 Title = dt["Title"].ToString()
                             });
            }
            return lst; 
        }

        public int DeleteByArticleEntityId(int articleEntityId)
        {
            return new Data.HoangPhapDataContext().CallArticleTranslationsDeleteByArticleEntityId(articleEntityId);
        }

        public int DeleteById(int id)
        {
            return new Data.HoangPhapDataContext().CallArticleTranslationsDeleteById(id);
        }

        public int DeleteByLanguageId(int languageId)
        {
            return new Data.HoangPhapDataContext().CallArticleTranslationsDeleteByLanguageId(languageId);
        }

        public int DeleteDynamic(string whereCondition)
        {
            return new Data.HoangPhapDataContext().CallArticleTranslationsDeleteDynamic(whereCondition);
        }

        public int Insert(System.String description, System.String title, System.String body, 
            System.Int32 languageId, System.Int32 articleEntityId, ref System.Int64 id)
        {
            return new Data.HoangPhapDataContext().CallArticleTranslationsInsert(description, title, body, languageId,
                articleEntityId, ref id);
        }

        public int InsertUpdate(System.Int64 id, System.String description, System.String title, 
            System.String body, System.Int32 languageId, System.Int32 articleEntityId)
        {
            return new Data.HoangPhapDataContext().CallArticleTranslationsInsertUpdate(id, description, title, 
                body, languageId, articleEntityId);
        }

        public int Update(System.Int64 id, System.String description, System.String title, System.String body, 
            System.Int32 languageId, System.Int32 articleEntityId)
        {
            return new Data.HoangPhapDataContext().CallArticleTranslationsUpdate(id, description, title,
                body, languageId, articleEntityId);
        }
    }
}
